package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.ResultCode;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RequestMapping("/admin/hosp/hospital")
@RestController
public class HospitalController {
    @Autowired
    DepartmentService departmentService;

    @Autowired
    HospitalService hospitalService;

    /**
     * 更新前端医院的状态 上/下线
     * @param id
     * @param status
     * @return
     */
    @GetMapping("updateStatus/{id}/{status}")
    public ResultCode.R updateStatus(@PathVariable String id, @PathVariable String status){
        hospitalService.updateStatus(id,status);
        return ResultCode.R.ok();
    }

    /**
     * 查询所有医院信息
     * @param limit
     * @param page
     * @param hospitalQueryVo
     * @return
     */
    @PostMapping("{page}/{limit}")
    public ResultCode.R findAll(
            @PathVariable Integer limit,
            @PathVariable Integer page,
            @RequestBody(required = false) HospitalQueryVo hospitalQueryVo){
        ResultCode.R r = hospitalService.findAll(limit,page,hospitalQueryVo);
        return r;
    }

    /**
     * 字典服务传入dictcode-->生成省下的所有城市
     * @param province
     * @return
     */
    @GetMapping("/getProvince/{province}")
    public ResultCode.R getProvince(@PathVariable String province){
        List<Dict> dicts = hospitalService.getDictByDictCode(province);
        return ResultCode.R.ok().data("list",dicts);
    }
    ///findByParentId/${provinceCode}
    @GetMapping("findByParentId/{provinceCode}")
    public ResultCode.R findByParentId(@PathVariable String provinceCode){
        List<Dict> dicts = hospitalService.findChildData(provinceCode);
        return ResultCode.R.ok().data("list",dicts);
    }

    /**
     * 通过Id查询Hospital信息。
     * @param id
     * @return
     */
    @GetMapping("getHospById/{id}")
    public ResultCode.R getHospById(@PathVariable String id){
        Hospital hospitalById = hospitalService.getHospById(id);
        HashMap<String, Object> hospital = new HashMap<>();
        hospital.put("hospital",hospitalById);
        hospital.put("bookingRule",hospitalById.getBookingRule());
        return ResultCode.R.ok().data("hospital",hospital);
    }

    /**
     * 通过hoscode获取 List<DepartmentVo> departmentVoList
     * @param hoscode
     * @return List<DepartmentVo> departmentVoList
     */
    @GetMapping("getDeptByHoscode/{hoscode}")
    public ResultCode.R getDeptByHoscode(@PathVariable String hoscode){
        List<DepartmentVo> departmentVoList = departmentService.getDeptByHoscode(hoscode);
        return ResultCode.R.ok().data("list",departmentVoList);
    }

}
